var t = require;
var i = module;
cc.Class({
    extends: cc.Component,
    properties: {wwordRoot: cc.Node, title: cc.Label, pbQuanXuan: cc.Prefab},
    onDestroy: function onDestroy() {
        this.winTimeout && clearTimeout(this.winTimeout);
    },
    start: function start() {
        var t = this;
        this.level = lGlobal.curLevel;
        var i = lGlobal.modelBundles[lGlobal.curModel],
            o = lGlobal.lvCfg.json[lGlobal.curModel][lGlobal.curLevel];
        if (i) {
            var r = o.lv;
            i.load("data/" + r + "/layout", cc.Prefab, function (i, o) {
                if (i) console.log(i);
                else {
                    var r = cc.instantiate(o);
                    (r.parent = t.node), (t.wwordRoot = r.getChildByName("line")), (t.allWWords = []);
                    for (var n = 0; n < t.wwordRoot._children.length; n++) {
                        var l = t.wwordRoot._children[n].getComponent("WWords");
                        l.setRightCB(t.wwordsRightCB.bind(t)),
                            l.setSingleWordRightCB(t.wwordRightCB.bind(t)),
                            t.allWWords.push(l);
                    }
                }
            });
        }
    },
    wwordsRightCB: function wwordsRightCB() {
        var t = this;
        this.isAllRight() &&
            (this.winTimeout = setTimeout(function () {
                console.log("You'r fxxking win"), window.ui.win({model: "WrongWordFind", lv: t.level});
            }, 1500)),
            soundMgr.playSound(soundMgr.right);
    },
    wwordRightCB: function wwordRightCB(t, i, o) {
        var r = o.node.convertToWorldSpaceAR(cc.Vec2.ZERO),
            n = this.node.convertToNodeSpaceAR(r),
            l = cc.instantiate(this.pbQuanXuan);
        (l.parent = this.node), (l.position = n);
    },
    isAllRight: function isAllRight() {
        for (var t = !0, i = 0; i < this.allWWords.length; i++) {
            if (!this.allWWords[i].isAllRight()) {
                t = !1;
                break;
            }
        }
        return t;
    },
    getTotalWrongCount: function getTotalWrongCount() {
        for (var t = 0, i = 0; i < this.allWWords.length; i++) {
            for (var o = 0; o < this.allWWords[i].allWWord.length; o++) {
                this.allWWords[i].allWWord[o].wrong && t++;
            }
        }
        return t;
    },
    getNowWrongCount: function getNowWrongCount() {
        for (var t = 0, i = 0; i < this.allWWords.length; i++) {
            for (var o = 0; o < this.allWWords[i].allWWord.length; o++) {
                this.allWWords[i].allWWord[o].wrong &&
                    this.allWWords[i].allWWord[o].label.string == this.allWWords[i].allWWord[o].wrong &&
                    t++;
            }
        }
        return t;
    },
    update: function update() {
        if (this.allWWords && this.title) {
            var t = this.getTotalWrongCount(),
                i = this.getNowWrongCount(),
                o = cc.js.formatStr("找到所有错字:%d/%d", t - i, t);
            this.title.string = o;
        }
    }
});
